import React, { PureComponent, Fragment } from 'react';
import {
  Card,
  Col,
  Form,
  Button,
  Input,
  Modal,
  message,
  Row
} from 'antd';
import { connect } from 'dva';
const FormItem = Form.Item;
const { TextArea } = Input;

@Form.create()
@connect()
class RepairAddForm extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      visible:false
    };
    this.user_id = sessionStorage.getItem('user_id');
    this.dispatch= this.props.dispatch;
  }
  submitEditValues=()=>{

    this.props.form.validateFields((err, values) => {
      if (!err) {
        let editObj = this.props.editObj;
        delete editObj["CurrentNodeName"];
        editObj.EquipmentName=values.EquipmentName;
        editObj.MaintainCause=values.MaintainCause;
        editObj.MaintainContent=values.MaintainContent;
        editObj.MaintainAdvice=values.MaintainAdvice;
        editObj.ApproveAdvice=values.ApproveAdvice;
        editObj.InspectContent=values.InspectContent;
        editObj.CompleteContent=values.CompleteContent;
        editObj.AcceptContent=values.AcceptContent;
        editObj.CheckContent=values.CheckContent;
        editObj.CompleteRemark=values.CompleteRemark;
        debugger
        this.dispatch({
          type: 'repair/fetchEditEquipment',
          payload: {
            // userID:this.user_id,
            userID:'BFBAAD3E-679F-426F-BF03-05DEE138DBA6',
            model:editObj
          },
          callback:response =>{
            if (response.status) {
              message.success('编辑成功');
              this.setState({visible:false});
              this.props.queryList();
              
            } else {
              message.error('编辑成功');
              console.log(response.ErrorMessage)
            }
          }
        });
      
      }
    });
       }
  componentDidMount() {
    this.props.OnRef(this,{type:'EditForm'});
  }
  render() {
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 21 },
      },
    };
    return (
      <Modal
      title="编辑"
      width={'70%'}
      destroyOnClose
      visible={this.state.visible}
      onOk={()=>{this.submitEditValues();}}
      onCancel={()=>{this.setState({visible:false});}}
       >
      <Form labelAlign="left">
      <Card
       title={
      <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
        维修申请
      </span>
    }
    style={{ margin: '5px 0' }}
  >
          <Row gutter={24} >
          <Col span={8}>
          <FormItem label="设施名称" {...formItemLayout}>
            {getFieldDecorator('EquipmentName', { rules: [{ required: true, message: '请填写设施名称！' }],initialValue: this.props.editObj.EquipmentName})(
              <Input placeholder="设施名称"/>
            )}
          </FormItem>
          </Col>
          </Row>
          <Row gutter={24}>
          <Col span={8}>
          <FormItem label="损坏原因" {...formItemLayout}>
            {getFieldDecorator('MaintainCause',{initialValue: this.props.editObj.MaintainCause} )(
              <TextArea placeholder="损坏原因"  rows={4}/>
            )}
          </FormItem>
          </Col>
          <Col span={8}>
          <FormItem label="维修内容" {...formItemLayout}>
            {getFieldDecorator('MaintainContent',{initialValue: this.props.editObj.MaintainContent})(
              <TextArea placeholder="维修内容" rows={4}/>
            )}
          </FormItem>
          </Col>
          <Col span={8}>
          <FormItem label="拟处理意见" {...formItemLayout}>
            {getFieldDecorator('MaintainAdvice',{initialValue: this.props.editObj.MaintainAdvice})(
              <TextArea placeholder="拟处理意见" rows={4}/>
            )}
          </FormItem>
          </Col>
          </Row>

          
          </Card>
      <Row gutter={24} style={{ margin: '5px 0' }}>
          <Col span={8}>
          <Card
       title={
      <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
        维修审批
      </span>
    }
  >

          <Row gutter={24}>

          <FormItem label="处理意见" {...formItemLayout}>
            {getFieldDecorator('ApproveAdvice',{initialValue: this.props.editObj.ApproveAdvice} )(
              <TextArea placeholder="处理意见"  rows={4}/>
            )}
          </FormItem>
          </Row>
          </Card>
          </Col>
          <Col span={8}>
          <Card
       title={
      <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
        维修抽查
      </span>
           }
            >
          <Row gutter={24}>
         
          <FormItem label="中间验收抽查内容" {...formItemLayout}>
            {getFieldDecorator('InspectContent',{initialValue: this.props.editObj.InspectContent} )(
              <TextArea placeholder="中间验收抽查内容"  rows={4}/>
            )}
          </FormItem>
          
          </Row>
          
          </Card>
          </Col>
         
          <Col span={8}>
          <Card
       title={
      <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
       维修验收
      </span>
           }
            >
          <Row gutter={24}>
         
          <FormItem label="监理单位验收意见" {...formItemLayout}>
            {getFieldDecorator('AcceptContent',{initialValue: this.props.editObj.InspectContent} )(
              <TextArea placeholder="监理单位验收意见"  rows={4}/>
            )}
          </FormItem>
         
          </Row>
          </Card>
          </Col>
          </Row>
          <Row gutter={24} style={{ margin: '5px 0' }}>
          <Col span={16}>
          <Card
       title={
      <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
         维修上报
      </span>
    }
  >

          <Row gutter={24}>
          <Col span={12}>
          <FormItem label="完成情况" {...formItemLayout}>
            {getFieldDecorator('CompleteContent',{initialValue: this.props.editObj.AcceptContent} )(
              <TextArea placeholder="完成情况"  rows={4}/>
            )}
          </FormItem>
          </Col>
          <Col span={12}>
          <FormItem label="备注" {...formItemLayout}>
            {getFieldDecorator('CompleteRemark',{initialValue: this.props.editObj.AcceptContent} )(
              <TextArea placeholder="备注"  rows={4}/>
            )}
          </FormItem>
          </Col>
          </Row>
          </Card>
          </Col>
          <Col span={8}>
          <Card
       title={
      <span style={{ borderLeft: '4px solid #3CB371', paddingLeft: '10px' }}>
        维修检查
      </span>
           }
            >
          <Row gutter={24}>
         
          <FormItem label="管理部门检查情况" {...formItemLayout}>
            {getFieldDecorator('CheckContent',{initialValue: this.props.editObj.CheckContent} )(
              <TextArea placeholder="管理部门检查情况"  rows={4}/>
            )}
          </FormItem>
          
          </Row>
          
          </Card>
          </Col>
          </Row>
      </Form>
       </Modal>
    );
  }
}

export default RepairAddForm;
